import { Inject, Pipe, PipeTransform, InjectionToken } from '@angular/core';

export const STATUS_OBJ = new InjectionToken<string>('status_obj');

/**
 * 状态管道符-中文
 */
@Pipe({ name: 'status' })
export class StatusPipe implements PipeTransform {
  constructor( @Inject(STATUS_OBJ) private _status: any) { }

  transform(value: any, type: string, defaultResult?: string, status?: any): string {
    defaultResult = defaultResult || '';
    status = status || this._status;
    if (value == null || value == undefined || value === '') return defaultResult;
    if (status == null || status == undefined) return defaultResult;
    const obj = status[type.toUpperCase()] || status[type.toLowerCase()];
    return obj[value] || defaultResult;
  }
}
